{{/* The "active" toggle here may delay rendering, so we only cache this side bar menu for bigger sites. */}}
{{ $sidebarCacheLimit := cond (isset .Site.Params.ui "sidebar_cache_limit") .Site.Params.ui.sidebar_cache_limit 2000 }}
{{ $shouldCache := ge (len .Site.Pages) $sidebarCacheLimit }}
{{ $sidebarCacheTypeRoot := cond (isset .Site.Params.ui "sidebar_cache_type_root") .Site.Params.ui.sidebar_cache_type_root false }}
{{ if $shouldCache }}
  {{ $mid := printf "m-%s" (.RelPermalink | anchorize) }}
  <script>
    $(function() {
    $("#td-section-nav a").removeClass("active");
    $("#td-section-nav #{{ $mid }}").addClass("active"); 
    $("#td-section-nav #{{ $mid }}-li span").addClass("td-sidebar-nav-active-item"); 
    $("#td-section-nav #{{ $mid }}").parents("li").addClass("active-path"); 
    $("#td-section-nav li.active-path").addClass("show"); 
    $("#td-section-nav li.active-path").children("input").prop('checked', true);
    $("#td-section-nav #{{ $mid }}-li").siblings("li").addClass("show");  
    $("#td-section-nav #{{ $mid }}-li").children("ul").children("li").addClass("show");  
    $("#td-sidebar-menu").toggleClass("d-none"); 
    });
  </script>
  {{ partialCached "sidebar-tree.html" . .FirstSection.RelPermalink }}
{{ else }}
  {{ partial "sidebar-tree.html" . }}
{{ end }}
